package com.asia5b.a5mall.order.adapter

import android.widget.LinearLayout
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel
import com.asia5b.a5mall.middleware.utils.DisplayUtils
import com.asia5b.a5mall.middleware.utils.WImageLoader
import com.asia5b.a5mall.middleware.widget.SqureImageView
import com.asia5b.a5mall.order.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/1/14.
 */
class OrderListImgAdapter(var list: ArrayList<AbsGoodsModel>) :
        BaseQuickAdapter<AbsGoodsModel, BaseViewHolder>(R.layout.item_orderlist_imgadapter, list) {
    val imgWidth by lazy { DisplayUtils.getScreenWidth(context) / 6 }
    override fun convert(helper: BaseViewHolder, item: AbsGoodsModel) {
        val iv_imgadapter_img = helper.getView<SqureImageView>(R.id.iv_imgadapter_img)
        /*
         重新设置图片宽高
          */
        val layoutParams = iv_imgadapter_img.layoutParams as LinearLayout.LayoutParams
        layoutParams.width = imgWidth.toInt()
        layoutParams.height = imgWidth.toInt()
        iv_imgadapter_img.layoutParams = layoutParams
        WImageLoader.displayRoundImage(item.absGoodsImageUrl, helper.getView(R.id.iv_imgadapter_img), 5)
    }

    override fun getItemCount(): Int {
        if (list.size > 4) {
            return 4
        }
        return super.getItemCount()
    }
}